import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:my_app/app/modules/image_widget/image_widget_controller.dart';
import 'package:my_app/app/core/theme/app_text_theme.dart';
import 'package:my_app/app/widgets/custom_image_widget.dart';
import 'package:my_app/app/widgets/custom_title_widget.dart';

/// image_widget_page.dart
///
/// Created by fuchuanwei on Tue Feb 21 2023.
///
/// Description:图片组件页面
///
class ImageWidgetPage extends GetView<ImageWidgetController> {
  @override
  Widget build(BuildContext context) {
    Get.put(ImageWidgetController());
    return Scaffold(
      appBar: AppBar(title: Text('图片')),
      body: ListView(
        padding: EdgeInsets.all(10.0),
        children: [
          imageDemo(),
          SizedBox(height: 20),
          paramsConfig(),
        ],
      ),
    );
  }

  ///图片演示效果
  Widget imageDemo() {
    return Card(
      child: Padding(
        padding: EdgeInsets.all(20.0),
        child: Column(
          children: [
            Text(
              '演示效果',
              style: cardTitle,
            ),
            SizedBox(height: 10),
            Obx(() => CustomImageWidget(
                  isCircle: controller.isCircle.value,
                  width: 100,
                  height: 100,
                  imageUrl: controller.imageUrl.value,
                  // imageUrl: 'assets/images/getx.png',
                ))
          ],
        ),
      ),
    );
  }

  ///参数配置
  Widget paramsConfig() {
    return Column(
      children: [
        Text(
          '参数配置',
          style: cardTitle,
        ),
        SizedBox(height: 20.0),
        Column(
          children: [
            CustomTitleWidget(
              title: '状态',
            ),
            SizedBox(height: 5.0),
            Obx(() => SizedBox(
                  width: double.infinity,
                  child: CupertinoSegmentedControl(
                    padding: EdgeInsets.zero,
                    groupValue: controller.selectedStateOption.value,
                    children: {0: Text('加载成功'), 1: Text('加载失败')},
                    onValueChanged: (int value) =>
                        controller.changeSelectedStateOption(value),
                  ),
                ))
          ],
        ),
        SizedBox(height: 20.0),
        Column(
          children: [
            CustomTitleWidget(
              title: '形状',
            ),
            SizedBox(height: 5.0),
            Obx(() => SizedBox(
                  width: double.infinity,
                  child: CupertinoSegmentedControl(
                    padding: EdgeInsets.zero,
                    groupValue: controller.selectedShapeOption.value,
                    children: {0: Text('方形'), 1: Text('圆形')},
                    onValueChanged: (int value) =>
                        controller.changeSelectedShapeOption(value),
                  ),
                ))
          ],
        ),
      ],
    );
  }
}
